package com.tudou.searchcontrol.config;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * 
 * @author zwu
 *
 */
public class ConfigBuilder{
	private Properties paraProps = new Properties();

	public ConfigBuilder(String confFile) {
		loadFile(confFile);
	}

	private void loadFile(String confFile) {
		if (confFile != null && confFile.trim().length() > 0) {
			InputStream is = this.getClass()
					.getResourceAsStream("/" + confFile);
			try {
				paraProps.load(is);
			} catch (FileNotFoundException e) {
				e.printStackTrace();
				System.err.println("不能读取配置文件" + confFile + "请确保文件路径正确");
			} catch (IOException e) {
				e.printStackTrace();
			} finally {
				try {
					is.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
	}

	

	/*
	 * 
	 */
	public String getProperty(String name) {
		String value = paraProps.getProperty(name);
        if (value == null) {
            throw new NullPointerException(name + " is null");
        }
        return value;
	}

}